<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Traits\TransFormer;
use App\Http\Requests\MessRequest;
use App\Services\ScoreService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class ScoreController extends Controller
{
    use TransFormer;

    protected $service;
    protected $mess;
    public function __construct(ScoreService $service,MessRequest $mess)
    {
        $this->service = $service;
        $this->mess = $mess;
    }

    /**
     * 三次检伤-ISS评分-保存/更新
     * @param Request $request
     * @return array
     */
    public function saveIssData(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->saveIssData();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1003001,$validator->errors()->first());
        }
        $result = $this->service->saveIssData($data);
        return $this->transFormer(200,'成功',$result);
    }

    public function getIssData(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->patientId();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1003004,$validator->errors()->first());
        }
        $result = $this->service->getIssData($data);
        return $this->transFormer(200,'成功',$result);
    }
}
